<?php

namespace app\controller;

use app\BaseController;
use app\Request;
use think\response\Json;

class User extends BaseController
{
    /**
     * 通过手机号码查询用户信息
     * @param Request $request
     * @return Json
     */
    public function get_user_by_mobile(Request $request): Json
    {
        $mobile = $request->param('mobile');
        try {
            $user = (new \app\model\User)->where('mobile', $mobile)
                ->field('id,mobile,username,avatar')
                ->find();
            if (empty($user)) {
                return apiResponse(404, '用户不存在');
            }
            return apiResponse(200, 'success', $user->toArray());
        } catch (\Exception $e) {
            return apiResponse(500, $e->getMessage());
        }
    }
}